package com.wanwu.channel.common.enums;

import java.util.LinkedHashMap;
import java.util.Map;

public enum ChannelRefundStatus {

    FAIL(0, "退款失败"),
    SUCCESS(1, "退款成功"),
    PROCESSING(2, "退款中"),
    @Deprecated
    CHANGE(3, "退款异常"),
    @Deprecated
    UNKNOWN(4, "退款关闭"),


    ;

    private Integer value;
    private String desc;

    ChannelRefundStatus(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static ChannelRefundStatus valueOf(int value) {

        for (ChannelRefundStatus type : ChannelRefundStatus.values()) {
            if (type.getValue() == value) {
                return type;
            }
        }
        return UNKNOWN;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static boolean isEndStatus(Integer code){
        if(FAIL.value.equals(code) || SUCCESS.value.equals(code)){
            return true;
        }
        return false;
    }

    public boolean check(Integer code){
        return this.getValue().equals(code);
    }

    public static Map<String, String> toMap() {
        Map<String, String> map = new LinkedHashMap<>();
        for (ChannelRefundStatus value : values()) {
            map.put(String.valueOf(value.value), value.desc);
        }
        return map;
    }
}
